package leetcode_200;

/**
 *@author 周杨
 *ExcelSheetColumnTitle_168 1 -> A
    2 -> B
    3 -> C
    ...
    26 -> Z
    27 -> AA
    28 -> AB 
    ...
Example 1:

Input: 1
Output: "A"
Example 2:

Input: 28
Output: "AB"
Example 3:

Input: 701
Output: "ZY"
 *describe: 考虑整除的特殊情况  AC 100%
 *2018年6月8日 下午5:26:51
 */
public class ExcelSheetColumnTitle_168 {

	public static void main(String[] args) {
		ExcelSheetColumnTitle_168 test=new ExcelSheetColumnTitle_168();
		System.out.println(test.convertToTitle(701));
		System.out.println(test.convertToTitle(52));
		System.out.println(test.convertToTitle(1));
		System.out.println(test.convertToTitle(28));

	}
	public String convertToTitle(int n) {
		StringBuilder sb=new StringBuilder();
		while(n!=0) {
			int now=n%26;
			char temp;
			if(now!=0) {
				temp=(char) ('@'+now);
				sb.insert(0, temp);
			}
			else {//整除
				sb.insert(0, 'Z');
				n=n/26-1;
				continue;
			}
			n/=26;
		}
        return sb.toString();
    }

}
